package com.soa.zuul.util;

import java.util.Arrays;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

public class JsonExclusionStrategy implements ExclusionStrategy {
	/**
	 * grid中只允许以下类型转Json
	 */
	public static String[] yes = new String[] { "STRING", "DATE", "DOUBLE",
			"BIGDECIMAL", "INTEGER", "FLOAT", "BYTE", "CHAR","BOOLEAN","TIMESTAMP","DATETIME","TIME","INT","LI" };
	public boolean shouldSkipClass(Class<?> clazz) {
		return false;
	}
	/**
	 * 不行允许set 类型的转Json
	 */
	public boolean shouldSkipField(FieldAttributes f) {
		String[] allTemple = f.getDeclaredType().toString().replaceAll("<", "")
				.replaceAll(">", "").split("\\.");
		String fitTemple = allTemple[allTemple.length - 1];
		return !Arrays.asList(yes).contains(fitTemple.toUpperCase());
	}
}
